"""百度AI开放平台异常类"""

from cn_api_adapters.common.exceptions import APIError, AuthenticationError, RequestError
from typing import Optional, Dict, Any


class BaiduAIError(APIError):
    """
    百度AI开放平台基础异常类
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI API请求失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIError"


class BaiduAIAuthError(AuthenticationError):
    """
    百度AI开放平台认证异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI开放平台认证失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIAuthError"


class BaiduAITokenError(BaiduAIAuthError):
    """
    百度AI开放平台Token异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI Token无效或已过期", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAITokenError"


class BaiduAIApiKeyError(BaiduAIAuthError):
    """
    百度AI开放平台API Key/Secret Key异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI API Key或Secret Key错误", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIApiKeyError"


class BaiduAIRateLimitError(RequestError):
    """
    百度AI开放平台限流异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
        retry_after: 建议重试时间（秒）
    """
    def __init__(self, message: str = "百度AI API请求频率超限", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None,
                 retry_after: Optional[int] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIRateLimitError"
        self.retry_after = retry_after


class BaiduAINotEnoughQuotaError(BaiduAIError):
    """
    百度AI开放平台配额不足异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI API调用配额不足", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAINotEnoughQuotaError"


class BaiduAIParamError(BaiduAIError):
    """
    百度AI开放平台参数异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI API参数错误", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIParamError"


class BaiduAIImageError(BaiduAIError):
    """
    百度AI开放平台图片处理异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI图片处理失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIImageError"


class BaiduAITextError(BaiduAIError):
    """
    百度AI开放平台文本处理异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI文本处理失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAITextError"


class BaiduAISpeechError(BaiduAIError):
    """
    百度AI开放平台语音处理异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI语音处理失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAISpeechError"


class BaiduAILanguageError(BaiduAIError):
    """
    百度AI开放平台语言处理异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI语言处理失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAILanguageError"


class BaiduAIUnitError(BaiduAIError):
    """
    百度AI开放平台UNIT对话异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI UNIT对话失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIUnitError"


class BaiduAIASRError(BaiduAIError):
    """
    百度AI开放平台语音识别异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI语音识别失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAIASRError"


class BaiduAITTSInvalidError(BaiduAIError):
    """
    百度AI开放平台语音合成异常
    
    Args:
        message: 错误消息
        error_code: 错误码
        response: API响应数据
    """
    def __init__(self, message: str = "百度AI语音合成失败", 
                 error_code: Optional[str] = None, 
                 response: Optional[Dict[str, Any]] = None):
        super().__init__(message, error_code, response)
        self.name = "BaiduAITTSInvalidError"